import {createSlice} from "@reduxjs/toolkit";

const counterStore = createSlice({
    name: 'counter',
    //定义数据
    initialState: {
        count: 0
    },
    //修改数据的同步方法
    reducers: {
        increment(state, action) {
            state.count += action.payload
        }
        , decrement(state, action) {
            state.count -= action.payload
        }
    }
})

// 按需导出同步方法
export const {increment, decrement} = counterStore.actions
// 默认导出reducer
const counterReducer = counterStore.reducer
export default counterReducer
